<?php 

ini_set("memory_limit", "12M");
if(!isset($_SESSION)) 
{ 
session_start(); 
} 

if(isset($_REQUEST['s_monitor']) and isset($_REQUEST['s_mode'])){
	$winH = 200;
	if(isset($_REQUEST['winH'])) $winH = $_REQUEST['winH'];
	$s_monitor = $_REQUEST['s_monitor'];
	$s_mode = $_REQUEST['s_mode'];
	if ($s_monitor==0){
		$sql = "Select cf.id,cf.`name` from configcamera cf ";
		if ($s_mode==0){
			$sql.= " where cf.go_mode=0 ";
		}else if ($s_mode==1){
			$sql.= " where cf.go_mode=1 ";
		}
	}else{
		$sql = "Select co.id,co.`name` from configcamera co, favourite f where co.id=f.camera_ID and f.monitor_ID=".$s_monitor;
		if ($s_mode==0){
			$sql.= " and co.go_mode=0 ";
		}else if ($s_mode==1){
			$sql.= " and co.go_mode=1 ";
		}
	}
	$sql .= " order by name";
	
	include '../connection/connection.php';
	set_time_limit(0);
	$listSearch = mysql_query($sql,$connection);
	$index = 0;
	$myCarmera = array();
	
	while ($row = mysql_fetch_array($listSearch)){
			$index+=1;
			array_push($myCarmera, array($row['id'],$row['name']));
				 ?>
				 <tr onclick="selectcamera(this,'chon<?=$index?>')">
				 	<td width="10%" align="center">
				 	<input type="checkbox" onclick="selectcamera(this,'chon<?=$index?>')" id="chon<?=$index?>" name="checkCamera[<?=$row['id']?>]" class="checkCamera"/>
				 	
				 	<td width="90%" class="last"><?=$row['name']?></td>
				 </tr> 
				 <?php  }
	if ($index>0 and $index<$winH/28) {
	 	foreach(range(0,$winH/28-$index) as $i){
	 		?>
	 		<tr>
		 	<td width="10%">&nbsp;</td>
		 	<td width="90%" class="last">&nbsp;</td>
		 	</tr>
	 	<?php }
	}  
	$_SESSION['myCarmera'] = $myCarmera;
	mysql_close($connection);
}

?>

